package com.okok.controller;

import com.entity.myInterface.UserDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/*
 * @author sky
 */
@Controller
@RequestMapping("/user")
public class User {
    private static Logger logger = LoggerFactory.getLogger(User.class);

   // @Autowired
  //  @Qualifier("UserDaoImp") //因为实现接口的类可能很多，所以要确定spring绑定的类
   // private UserDao userDao;
  //  private Gson gson=new Gson();

    /*
     *
     * 登录
     * @author sky
     * @date 2018/9/11 16:30
     * @param [loginUserDTO, request]
     * @return java.lang.String
     */
 /*   @RequestMapping(value = "/bglogin.action", method = RequestMethod.POST)
    @ResponseBody
    public String login(@RequestBody UserDTO loginUserDTO, HttpServletRequest request){
        logger.info("yayayayayayayaya");
        //根据用户名查询用户，是否存在以及信息
        UserDTO userDTO = userDao.login(loginUserDTO.getLoginname());
        JsonObject object = new JsonObject();
        //如果存在
        if(userDTO !=null){
            if(loginUserDTO.getPwd().equals(userDTO.getPwd())){
                //如果密码正确
                //将用户信息放入到会话中...
                request.getSession().setAttribute("user", userDTO);
                object.addProperty("status", "success");
            }else{
                //如果密码错误
                object.addProperty("status", "fail");
            }
        }else{
            //如果不存在，代码邮箱和密码输入有误
            object.addProperty("status", "no");
        }
        return object.toString();
    }*/


    /**
     * 注册
     * @return
     */
  /*  @RequestMapping(value = "/register.action", method = RequestMethod.POST)
    @ResponseBody
    public String register(@RequestBody UserDTO loginUserDTO, HttpServletRequest request){
        //根据用户名查询用户，是否存在以及信息
        UserDTO userDTO = userDao.login(loginUserDTO.getLoginname());
        JsonObject object = new JsonObject();
        //如果存在
        if(userDTO !=null){
            object.addProperty("status", "fail");
        }else{
            //调用注册方法
            userDao.register(loginUserDTO);
            object.addProperty("status", "success");
        }
        return object.toString();
    }


    @RequestMapping(value = "/updataPWD.action", method = RequestMethod.POST)
    @ResponseBody
    public String updataPWD(@RequestBody UserDTO loginUserDTO, HttpServletRequest request){
        JsonObject object = new JsonObject();
        //修改条数为1时为修改成功
        if (userDao.updataPWD(loginUserDTO) == 1L) {
            object.addProperty("status", "success");
        } else {
            object.addProperty("status", "fail");
        }
        return object.toString();
    }*/




}
